package com.tiger.utils;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author andy
 *
 */
public class ClassUtils {

	private final static Logger LOGGER = LoggerFactory.getLogger(ClassUtils.class);
	
	public static void fill(Object target, Object src) {
		src.getClass().getSuperclass();
		Class<?> cls = src.getClass();
		while(cls != null) {
			Field[] fields = cls.getDeclaredFields();
			for(Field f : fields) {
				if(Modifier.isStatic(f.getModifiers())) {
					continue;
				}
				try {
					f.setAccessible(true);
					f.set(target, f.get(src));
				} catch (IllegalArgumentException | IllegalAccessException e) {
					LOGGER.error("fill the obj error", e);
				}
			}
			cls = cls.getSuperclass();
		}
	}
}
